﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OdeToFood.Models;
using OdeToFood.Queries;
using System.Threading;

namespace OdeToFood.Controllers
{
    public class HomeController : Controller
    {
        OdeToFoodDB _db = new OdeToFoodDB();



        public PartialViewResult Search(string q) 
        {
            var restaurants = _db.Restaurants
                .Where(r => r.Name.Contains(q) || String.IsNullOrEmpty(q)).Take(10);

            return PartialView("_RestaurantSearchResults",restaurants);
        }



        public PartialViewResult LatestReview() 
        {
            Thread.Sleep(2000);
            var review = _db.Reviews.FindTheLatest(1).Single();
            return PartialView("_Review", review);
            
        }

        [Authorize]
        public ViewResult Index()
        {
            /* ViewBag.Message = String.Format("URL actual = {0}"+"/"+"{1}"+"/"+"{2}", 
                                            RouteData.Values["controller"], 
                                            RouteData.Values["action"],
                                            RouteData.Values["id"]);            
            var Model = new Review()
            {
                //Name = "Pizza Libre",
                Rating = 9
            };*/


            ViewBag.Message = "Welcome to Ode to Food";
            return View();
        }

        public ActionResult About()
        {

            ViewBag.Lugar = "Bahia Blanca, Argentina";
            return View();
            
        }
    }
}
